package com.jindy.module.versionmanagement.service.impl;

import com.jindy.common.core.domain.entity.SysUser;
import com.jindy.common.utils.DateUtils;
import com.jindy.common.utils.SecurityUtils;
import com.jindy.module.versionmanagement.domain.VersionManagement;
import com.jindy.module.versionmanagement.mapper.VersionManagementMapper;
import com.jindy.module.versionmanagement.service.VersionManagementService;
import com.jindy.system.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 版本管理Service业务实现类
 *
 * @author 朝夕
 * @date 2022-12-16
 */

@Service
public class VersionManagementServiceImpl implements VersionManagementService {

    @Autowired
    private ISysUserService sysUserService;

    @Resource
    VersionManagementMapper versionManagementMapper;


    /**
     * 查询报备列表
     *
     * @param version 报备
     * @return 报备列表
     */
    @Override
    public List<VersionManagement> selectVersionList(VersionManagement version) {
        return versionManagementMapper.selectVersionList(version);
    }

    /**
     * 查询报备
     *
     * @param id 报备主键
     * @return 报备数据
     */
    @Override
    public VersionManagement selectVersionById(String id) {
        return versionManagementMapper.selectVersionById(id);
    }


    /**
     * 新增报备数据
     *
     * @param version 报备
     * @return 结果
     */
    @Override
    public int insertVersion(VersionManagement version)
    {
        SysUser sysUser = sysUserService.selectUserByUserName(SecurityUtils.getUsername());
        version.setCreateBy(sysUser.getUserName());
        version.setCreateTime(DateUtils.getNowDate());
        return versionManagementMapper.insertVersion(version);
    }

    /**
     * 修改报备数据
     *
     * @param version
     * @return 结果
     */
    @Override
    public int updateVersion(VersionManagement version) {
        SysUser sysUser = sysUserService.selectUserByUserName(SecurityUtils.getUsername());
        version.setUpdateBy(sysUser.getUserName());
        version.setUpdateTime(DateUtils.getNowDate());
        return versionManagementMapper.updateVersion(version);
    }

    /**
     * 删除报备数据
     *
     * @param id 报备主键
     * @return 结果
     */
    @Override
    public int deleteVersionById(String id)
    {
        return versionManagementMapper.deleteVersionById(id);
    }

    /**
     * 批量删除
     *
     * @param ids 需要删除的主键
     * @return 结果
     */
    @Override
    public int deleteVersionByIds(String[] ids)
    {
        return versionManagementMapper.deleteVersionByIds(ids);
    }

}
